package demo1.demo2.test;

import entity.People;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Controller;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: DELL
 * Date: 2023-05-05
 * Time: 17:13
 */
@Controller
public class PeopleCenter2 implements BeanNameAware, BeanPostProcessor, InitializingBean {

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("这是 BeanPostProcessor 后置初始化之前的处理");
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("这是 BeanPostProcessor 后置初始化之后的处理");
        return bean;
    }


    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("这是 InitializingBean 的前置初始化方法");
    }

    @Override
    public void setBeanName(String s) {
        System.out.println("执行了 BeanNameAware 各种通知 : " + s);
    }




    // xml 文件中的 init-method = "下面这个方法名" , 否者找不到
   public void myInit() {
        System.out.println("这是 XML 配置文件中的初始化方法");
    }

    // 注解方式的初始化方法
    @PostConstruct
    public void doPostConstruct() {
        System.out.println("这是 PostConstruct 注解方式初始化");
    }

    // Bean 对象的基本方法
    public void fun() {
        System.out.println("这是 PeopleCenter2 的 fun 方法");
    }

    // Bean 的 XML 销毁方法, xml 文件中 destroy-method = "下面这个方法名", 否则找不到
    public void myDestroy() {
        System.out.println("这是 XML 配置文件的 Bean 的销毁方法");
    }

    // 注解方式销毁 Bean
    @PreDestroy
    public void doPreDestroy() {
        System.out.println("这是 PreDestroy 注解方式销毁 Bean");
    }

}
